/*---------------------------------------------------------------------------
 * Name:    S32K3xx_bootheader.h
 * Purpose: S32K3xx Boot Header definition
 * Rev.:    1.0.0
 *---------------------------------------------------------------------------*/
/*
 * Copyright (c) 2021 Arm Limited or its affiliates. All rights reserved.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Licensed under the Apache License, Version 2.0 (the License); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef S32K3xx_BOOTHEADER_H
#define S32K3xx_BOOTHEADER_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef struct
{
  const uint32_t Header;                         /* Offset: 0x000  Boot Header (0x5AA55AA5) */
  const uint32_t BootConfig;                     /* Offset: 0x004  Boot Configuration Word */
  const uint32_t Reserved0;                      /* Offset: 0x008  Reserved */
  const void*    CM7_0_StartAddress;             /* Offset: 0x00C  CM7_0 Application Start Address */
  const uint32_t Reserved1;                      /* Offset: 0x010  Reserved */
  const void*    CM7_1_StartAddress;             /* Offset: 0x014  CM7_1 Application Start Address */
  const uint32_t Reserved2;                      /* Offset: 0x018  Reserved */
  const void*    CM7_2_StartAddress;             /* Offset: 0x01C  CM7_2 Application Start Address */
  const uint32_t Reserved3;                      /* Offset: 0x020  Reserved */
  const void*    LC_ConfigAddress;               /* Offset: 0x024  LC Configuration Word Address */
  const void*    CM7_3_StartAddress;             /* Offset: 0x01C  CM7_3 Application Start Address */
  const uint32_t HseFw;                          /* Offset: 0x02C  FW-IMG: NXP supplied encrypted HSE FW image address */
  const void*    AppBL;                          /* Offset: 0x030  Pointer to AppBL structure for secure boot*/
  const uint32_t Reserved5[3];                   /* Offset: 0x034  12 bytes reserved */
  const uint32_t AppRecoveryAddr;                /* Offset: 0x040  Pointer to start address of application core for secure recovery mode */
  const uint32_t AppRecoverySize;                /* Offset: 0x044  Length of Recovery Application */
  const uint32_t Reserved6[39];                  /* Offset: 0x048  156 bytes reserved */
  const uint32_t RandomVector[3];                /* Offset: 0x0E4  Initialization vector value to be used in calculation of GMAC */
  const uint32_t GMAC[4];                        /* Offset: 0x0F0  The AES-GMAC of the entire IVT structure calculated using ADKP-SHA */
} S32K3xx_bootheader_t;

#define S32K3XX_APPBL_APP
#define S32K3XX_APPBL_RandomVector
#define S32K3XX_APPBL_GMAC

typedef struct 
{
  const uint8_t  Header;                         /* Offset: 0x00  AppBL header tag (0xD5) */
  const uint8_t  Reserved0;                      /* Offset: 0x01  Reserved */
  const uint8_t  Reserved1;                      /* Offset: 0x02  Reserved */
  const uint8_t  Version;                        /* Offset: 0x03  AppBL version (0x60) */
  const uint32_t Reserved2;                      /* Offset: 0x04  Reserved */
  const void*    AppStartAddress;                /* Offset: 0x08  Application Start Address(in Flash) */
  const uint32_t AppSize;                        /* Offset: 0x0C  Application Size(N) */
  const uint32_t CoreId;                         /* Offset: 0x10  Core ID */
  const uint8_t  Reserved3[44];                  /* Offset: 0x14  44 bytes reserved*/
  S32K3XX_APPBL_APP                              /* Offset: 0x40  AppBL App structure */
  S32K3XX_APPBL_RandomVector                     /* Offset: 0x40+N  12 bytes random vector */
  S32K3XX_APPBL_GMAC                             /* Offset: 0x4C+N  16 bytes GMAC TAG */
} S32K3xx_AppBL_t;

#ifdef __cplusplus
}
#endif

#endif /* S32K3xx_BOOTHEADER_H */
